package com.sgb.goods.utils.base.adapter;


import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * PagerAdapter的基类
 * @author cyj
 */
public class BasePagerAdapter<T extends Fragment> extends FragmentStateAdapter {

    protected List<T> mDataList;

    public BasePagerAdapter(FragmentActivity fragmentActivity) {
        super(fragmentActivity);
    }

    public BasePagerAdapter(Fragment fragment) {
        super(fragment);
    }

    @NonNull
    @NotNull
    @Override
    public Fragment createFragment(int position) {
        return mDataList.get(position);
    }

    @Override
    public int getItemCount() {
        return mDataList != null ? mDataList.size() : 0;
    }

    /**
     * 设置数据列表
     *
     * @param dataList 数据列表
     */
    public void setDataList(List<T> dataList) {
        mDataList = dataList;
        notifyDataSetChanged();
    }
}
